<template>
  <div class="jb-dialog" v-if="visible">
    <div class="title">举报
      <img src="@/assets/close.png" @click.stop="close">
    </div>
    <div class="jb-item-all">
      <div class="jb-item" v-for="(item,index) in reportList" :key="index" @click="gotoReport(item)">
        {{ item.label }}
      </div>
    </div>
  </div>
</template>

<script>
import {reportList, report} from '@/api/share.js'
import {antiShake} from '@/utils/antie.js'//防抖函数
export default {
  name: "report",
  props: {
    // visible: {
    //   type: Boolean
    // },
    type: {
      type: String
    },
     token: {
      type: String
    }
  },
  data() {
    return {
      reportList: [],
      commentItem: {},
      visible:false
    }
  },
  mounted() {
    this.getReportList()
  },
  methods: {
    close() {
      this.$emit('close')
    },
    init(item) {
      this.visible = true
      this.commentItem = item
      
    },
    getReportList() {
      let data={
        token:this.token
      }
      reportList(data).then((res) => {
        this.reportList = res.data
      })
    },
    gotoReport: antiShake(  function (item){
      let data = {
        auditType: this.type === 'content' ? 1 : 2, //1内容 2评论
        reportType: item.value,
        commentsId: this.commentItem.id,//内容的id
        token:this.token
      }
      report(data).then((res) => {
        if (res.code == 0) {
          this.$toast.success("举报成功");
        } else if (res.code == 1) {
          this.$toast.fail(res.msg);
        }
      })
    })
  }
}
</script>

<style scoped lang="less">
.jb-dialog {
  z-index: 999;
  position: absolute;
  bottom: 35px;
  right: 5px;
  width: 268px;
  height: 177.05px;
  border-radius: 17px;
  //background: linear-gradient(180deg, rgba(255, 255, 255, 1) 0%, rgba(255, 184, 112, 0.19) 0%, rgba(255, 141, 26, 0) 100%);
  background-image: url("~@/assets/jubg.png");
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;

  .title {
    font-size: 20px;
    font-weight: 500;
    letter-spacing: 0px;
    line-height: 28.96px;
    color: rgba(0, 0, 0, 1);
    text-align: center;
    padding: 10px 10px 0 10px;
    position: relative;

    > img {
      width: 10px;
      height: 10px;
      position: absolute;
      right: 17px;
      top: 17px;
    }
  }

  .jb-item-all {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    padding: 8px;

    .jb-item {
      width: calc((100% - 10px) / 2);
      height: 28px;
      margin-right: 10px;
      line-height: 28px;
      border-radius: 36px;
      background: rgba(255, 231, 191, 1);
      text-align: center;
      margin-bottom: 12px;
    }

    .jb-item:nth-of-type(2n + 0) {
      margin-right: 0;
    }

  }

}
</style>